package com.dream.config;

import com.dream.web.interceptor.WebSocketLoginInterceptor;
import com.dream.web.websocket.ConsoleWebSocket;
import com.dream.web.websocket.GroupMemberWebSocket;
import com.dream.web.websocket.PersonalWebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    
    @Autowired private PersonalWebSocket personalCenterWebSocket;
    @Autowired private ConsoleWebSocket consoleWebSocket;
    @Autowired private GroupMemberWebSocket groupMemberWebSocket;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //个人中心的webSocket
        //registry.addHandler(personalCenterWebSocket, "/personalCenterWebSocket").addInterceptors(new HttpSessionHandshakeInterceptor());
        //registry.addHandler(personalCenterWebSocket, "/sockjs/personalCenterWebSocket").addInterceptors(new HttpSessionHandshakeInterceptor()).withSockJS();
        
        //控制台的webSocket
        registry.addHandler(consoleWebSocket, "/consoleWebSocket").addInterceptors(new WebSocketLoginInterceptor()).setAllowedOrigins("*");
        registry.addHandler(consoleWebSocket, "/sockjs/consoleWebSocket").addInterceptors(new WebSocketLoginInterceptor()).setAllowedOrigins("*").withSockJS();

        //群组列表的webSocket
        //registry.addHandler(groupWebSocket, "/groupListWebSocket").addInterceptors(new HttpSessionHandshakeInterceptor());
        //registry.addHandler(groupWebSocket, "/sockjs/groupListWebSocket").addInterceptors(new HttpSessionHandshakeInterceptor()).withSockJS();

        //群内成员列表的webSocket
        registry.addHandler(groupMemberWebSocket, "/groupMemberListWebSocket").addInterceptors(new WebSocketLoginInterceptor()).setAllowedOrigins("*");
        registry.addHandler(groupMemberWebSocket, "/sockjs/groupMemberListWebSocket").addInterceptors(new WebSocketLoginInterceptor()).setAllowedOrigins("*").withSockJS();
    }
}